package chapter1.date.task;
/*
6：学士后结业考试的时间是每月倒数第二个周六上午8点，输出今年的考试时间
，用yyyy/MM/dd hh时 的格式输出
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Task6 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat a = new SimpleDateFormat("yyyy/MM/dd hh时");
        System.out.print("请输入年份：");
        String year;
        while (!(year = input.next()).matches("\\d{4}"))
            System.out.println("输入错误，请重新输入：");
        calendar.set(Calendar.YEAR, Integer.parseInt(year));
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.HOUR, 8);
        System.out.println("考试时间为：");
        while (calendar.get(Calendar.YEAR) <= Integer.parseInt(year)) {
            int maxMonthDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);   //这个月中最大的天数
            calendar.set(Calendar.DAY_OF_MONTH, maxMonthDay); //把时间设到这个月的最后一天
            int weekDay = calendar.get(Calendar.DAY_OF_WEEK);  //这个月最后一天是星期几
            if (weekDay == 7)  //恰好是周六
                calendar.add(Calendar.DAY_OF_MONTH, -7);
            else
                calendar.add(Calendar.DAY_OF_MONTH, -(weekDay + 7));    
            System.out.println(a.format(calendar.getTime()));
            calendar.add(Calendar.MONTH, 1);
        }


    }
}
